home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Topik / Topik - Disk 16 - KnowAboutIt (19xx)(Topik Public Domain)(PD)[WB].zip / Topik - Disk 16 - KnowAboutIt (19xx)(Topik Public Domain)(PD)[WB].adf / MicroRayDbw / random.c < prev    next >
C/C++ Source or Header  |  1988-12-11  |  3KB  |  79 lines

  1. /************************************************************************
  2.  *                                    *
  3.  *            Copyright (c) 1988, David B. Wecker            *
  4.  *                All Rights Reserved                *
  5.  *                                    *
  6.  * This file is part of DBW_uRAY                    *
  7.  *                                    *
  8.  * DBW_uRAY is distributed in the hope that it will be useful, but    *
  9.  * WITHOUT ANY WARRANTY. No author or distributor accepts        *
  10.  * responsibility to anyone for the consequences of using it or for    *
  11.  * whether it serves any particular purpose or works at all, unless    *
  12.  * he says so in writing. Refer to the DBW_uRAY General Public        *
  13.  * License for full details.                        *
  14.  *                                    *
  15.  * Everyone is granted permission to copy, modify and redistribute    *
  16.  * DBW_uRAY, but only under the conditions described in the        *
  17.  * DBW_uRAY General Public License. A copy of this license is        *
  18.  * supposed to have been given to you along with DBW_uRAY so you    *
  19.  * can know your rights and responsibilities. It should be in a file    *
  20.  * named COPYING. Among other things, the copyright notice and this    *
  21.  * notice must be preserved on all copies.                *
  22.  ************************************************************************
  23.  *                                    *
  24.  * Authors:                                *
  25.  *    DBW - David B. Wecker                        *
  26.  *                                    *
  27.  * Versions:                                *
  28.  *    V1.0 881023 DBW    - First released version            *
  29.  *    V1.1 881110 DBW - Fixed scan coherence code            *
  30.  *    V1.2 881125 DBW - Removed ALL scan coherence code (useless)    *
  31.  *              added "fat" extent boxes            *
  32.  *                                    *
  33.  ************************************************************************/
  34.  
  35. #include "uray.h"
  36.  
  37. /************************************************************************/
  38. /************ random number generator (see uray.h for random table ******/
  39. /************************************************************************/
  40.  
  41. /*
  42.  * srandom(x)    - sets a random seed starting point (long int)
  43.  * random()    - returns next random long int (between 0 and 0x7FFFFFFF)
  44.  * rnd()    - return next random FLTDBL (between 0 and 1)
  45.  */
  46.  
  47. srandom( x )
  48. unsigned x;
  49.     {
  50.     register  int i;
  51.  
  52.     /* rebuild the random table */
  53.     randtbl[ 0 ] = x;
  54.     for( i = 1; i < 63; i++ )
  55.     randtbl[i] = 1103515245*randtbl[i - 1] + 12345;
  56.  
  57.     fptr = &randtbl[ 1 ];
  58.     rptr = &randtbl[ 0 ];
  59.     }
  60.  
  61. long random()
  62.     {
  63.     long        i;
  64.     
  65.     *fptr += *rptr;
  66.     i = (*fptr >> 1)&0x7fffffff;    /* chucking least random bit */
  67.     if(  ++fptr  >=  end_ptr  )  {
  68.     fptr = randtbl;
  69.     ++rptr;
  70.     }
  71.     else  if(  ++rptr  >=  end_ptr  )  rptr = randtbl;
  72.     return( i );
  73.     }
  74.  
  75. FLTDBL rnd() {
  76.     return ((FLTDBL)random()) / 2147483647.0;
  77.     }
  78.  
  79.